{% extends "base.html" %}

{% block formValidator %}{% end %}
{% block custom_style %}
<style type="text/css">
    form{width:280px;height:120px;margin:30px auto 0;}
    form div label{float:left;display:block;width:65px;font-size:16px;padding-top:6px;}
    form div{margin:8px auto;}
    form div.input input{height:21px;padding:2px 3px;}
    form div.input img{cursor:pointer}
    #username,#password{width:200px;}
    #code{width:68px}
</style>
{% end %}


{% block content %}
<div class="easyui-dialog" title="用户登录" style="width:380px;height:240px" data-options="closable:false,iconCls:'icons-lock-lock',buttons:[{text:'登录',iconCls:'icons-user-user_go',handler:login}]">
	<form id='form' method="post">
        {% raw xsrf_form_html() %}
		<div class="input">
			<label for="username">用户名:</label>
	        <input type="text" name="username" id="username"  />
		</div>
		<div class="input">
			<label for="password">密&nbsp;&nbsp;码:</label>
	        <input type="password" name="password" id="password" />
		</div>
		<div class="input">
			<label for="code">验证码:</label>
	        <input type="text" name="code" id="code" size="4" />
	        <span style="margin-left:10px"><img id="code_img" align="top" onclick="changeCode()" src="" title="点击切换验证码"></span>
		</div>
	</form>
</div>

<script type="text/javascript">
$(function(){
	$('input:text:first').focus();
	$('form').keyup(function(event){
		if(event.keyCode ==13){
			login();
		}
	});
})
var changeCode = function(){
	var that = document.getElementById('code_img');
	that.src = that.src + '&' + Math.random();
}
var login = function(){
	if(!$('#username').val()){
		$.messager.alert('提示信息', '请填写用户名', 'error');
		return false;
	}
	if(!$('#password').val()){
		$.messager.alert('提示信息', '请填写密码', 'error');
		return false;
	}
	if(!$('#code').val()){
		$.messager.alert('提示信息', '请填写验证码', 'error');
		return false;
	}
	$.post('/admin/login', $("form").serialize(), function(data){
		if(data.error != 0){
			$.messager.alert('提示信息', data.msg, 'error');
			changeCode();
		}else{
			$.messager.progress({text:'加载中，请稍候...'});
			window.location.href = data.url;
		}
	},'json');
	return false;
}
</script>
{% end %}
